package com.ruoyi.system.domain.vo;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class MultiLatitudVo {

    @Data
    @ApiModel("多维度")
    public static class Result {
        private String xm;
        private String jzlsh;
        @ApiModelProperty("住院号")
        private String zl_jbxx_zyh;
        @ApiModelProperty("主要医疗付费方式_")
        private String zl_jbxx_ylff;
        @ApiModelProperty("入院途径_")
        private String zl_jbxx_rytj;
        @ApiModelProperty("住院日期_")
        private String zl_jbxx_zytime;
        @ApiModelProperty("出院日期_")
        private String zl_jbxx_cyrq;
        @ApiModelProperty("住院年龄_")
        private String zl_jbxx_zyage;
        @ApiModelProperty("住院天数_")
        private String zl_jbxx_zyts;
        @ApiModelProperty("离院方式_")
        private String zl_jbxx_lyfs;
        @ApiModelProperty("住院总费用_")
        private String zl_jbxx_zyzfy;
//        @ApiModelProperty("主要诊断名称_")
//        private List<Zdmc> zl_jbxx_zdmc;

        @ApiModelProperty("主要诊断名称_")
        private String zl_jbxx_zdmc;

        public String getZl_jbxx_zdmc() {
            if (CollectionUtil.isNotEmpty(zl_jbxx_zdmcList)) {
                return zl_jbxx_zdmcList.stream().map(Zdmc::getZdmc).collect(Collectors.toList()).toString();
            }
            return zl_jbxx_zdmc;
        }

        @ApiModelProperty("主要诊断名称_")
        private List<Zdmc> zl_jbxx_zdmcList;

        @ApiModelProperty("主要诊断编码_")
        private String zl_jbxx_zdbm;
        @ApiModelProperty("死亡日期_")
        private String zl_jbxx_die_t;
        @ApiModelProperty("死亡原因_")
        private String zl_jbxx_die_r;
        @ApiModelProperty("发病时间（或最后正常时间）_")
        private String zl_fbqk_fbsj_time;
        @ApiModelProperty("到院时间_")
        private String zl_fbqk_dy_time;
        @ApiModelProperty("收缩压_")
        private String zl_rypg_sbp;
        @ApiModelProperty("舒张压_")
        private String zl_rypg_dbp;
        @ApiModelProperty("颈部血管检查_")
        private String zl_rypg_ceacas_jc;
        @ApiModelProperty("是否给予双重抗血小板聚集治疗？_")
        private String zl_jrzt_ywzl_dual;
        @ApiModelProperty("使用的药物为_")
        private String zl_jrzt_ywzl_dual_yw;
        @ApiModelProperty("48小时内是否给予抗血小板药物治疗_")
        private String zl_jrzt_ywzl_i48_plt;
        @ApiModelProperty("出院用药_")
        private String zl_cypg_cyyy;
        @ApiModelProperty("ONT_")
        private String zl_jmrs_ont;
        @ApiModelProperty("DNT_")
        private String zl_jmrs_dnt;
        @ApiModelProperty("OPT_")
        private String zl_jrzt_opt;
        @ApiModelProperty("DPT_")
        private String zl_jrzt_dpt;
        @ApiModelProperty("DRT_")
        private String zl_jrzt_drt;
        @ApiModelProperty("手术开始时间（选填）_")
        private String zl_ceacas_ss_time;
        @ApiModelProperty("手术部位（选填）_")
        private String zl_ceacas_ss_ssbw;
        @ApiModelProperty("手术采取方式_")
        private String zl_ceacas_ss_fs;
        @ApiModelProperty("CEA手术并发症_")
        private String zl_ceacas_cea_bfz;
        @ApiModelProperty("手术开始时间_")
        private String zl_ncx_t_ss;
        @ApiModelProperty("系统计算发病到手术开始时间_")
        private String zl_ncx_oot;
        @ApiModelProperty("系统计算到院到开始手术时间_")
        private String zl_ncx_dot;
        @ApiModelProperty("麻醉方式_")
        private String zl_ncx_mz;
        @ApiModelProperty("手术方式_")
        private String zl_ncx_ss;
        @ApiModelProperty("病程列表")
        private List<BcLb> bclb;
        @ApiModelProperty("入院科室")
        private String ryks;
        @ApiModelProperty("客观所见")
        private String kgsj;
        @ApiModelProperty("主观提示")
        private String zgts;
        @ApiModelProperty("检查项目名称")
        private String jcxmmc;

//        public String getKgsj() {
//            if (CollectionUtil.isNotEmpty(yxResultList)) {
//                return yxResultList.stream().map(YxResult::getKgsj).collect(Collectors.toList()).toString();
//            }
//            return kgsj;
//        }

//        public String getZgts() {
//            if (CollectionUtil.isNotEmpty(yxResultList)) {
//                return yxResultList.stream().map(YxResult::getZgts).collect(Collectors.toList()).toString();
//            }
//            return zgts;
//        }
//
//        public String getJcxmmc() {
//            if (CollectionUtil.isNotEmpty(yxResultList)) {
//                return yxResultList.stream().map(YxResult::getJcxmmc).collect(Collectors.toList()).toString();
//            }
//            return jcxmmc;
//        }
//
//        private List<YxResult> yxResultList;

//        public String getZl_jbxx_zdmc() {
//            if (CollectionUtil.isNotEmpty(zl_jbxx_zdmcList)) {
//                StringBuffer str = new StringBuffer();
//                for (Zdmc zdmc : zl_jbxx_zdmcList) {
//                    str.append(zdmc.getZdmc()).append(",");
//                }
//                return str.substring(0, str.length() - 1);
//            }
//            return null;
//        }

        public String getZl_jbxx_rytj() {
            if (StrUtil.isNotEmpty(zl_jbxx_rytj)) {
                //1：门诊入院；2：急诊入院；3：其他医疗机构转入；9：其他
                if ("1".equals(zl_jbxx_rytj)) {
                    return "门诊入院";
                }
                if ("2".equals(zl_jbxx_rytj)) {
                    return "急诊入院";
                }
                if ("3".equals(zl_jbxx_rytj)) {
                    return "其他医疗机构转入";
                }
                if ("9".equals(zl_jbxx_rytj)) {
                    return "其他";
                }
            }
            return zl_jbxx_rytj;
        }

        public List<String> getBclb() {
            if (CollectionUtil.isNotEmpty(bclb)) {
                return bclb.stream().map(BcLb::getProgressMessage).collect(Collectors.toList());
            }
            return null;
        }

        @Data
        public static class YxResult{
            @ApiModelProperty("客观所见")
            private String kgsj;
            @ApiModelProperty("主观提示")
            private String zgts;
            @ApiModelProperty("检查项目名称")
            private String jcxmmc;
        }

        @Data
        public static class Zdmc {
            private String zdmc;
            private String zdbm;
        }

        @Data
        public static class BcLb {
            @ApiModelProperty("患者流水号")
            private String progressGuid;
            @ApiModelProperty("文书类型")
            private String progressType;
            @ApiModelProperty("文书")
            private String progressMessage;

            @ApiModelProperty("文书创建时间")
            @JsonFormat(pattern = "yyyy-MM-dd")
            private Date recordTimeFormat;

//            public String getProgressMessage() {
//                if (progressMessage != null) {
//                    try {
//                        String result = clob2String(progressMessage);
//                        return result;
//                    }catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                }
//                return null;
//            }
        }
    }

    private static String clob2String(Clob clob) throws SQLException, IOException {
        String reString = "";
        Reader is = clob.getCharacterStream();// 得到流
        BufferedReader br = new BufferedReader(is);
        String s = br.readLine();
        StringBuffer sb = new StringBuffer();
        while (s != null) {
            // 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
            sb.append(s);
            s = br.readLine();
        }
        reString = sb.toString();
        return reString;
    }


    @Data
    @ApiModel("MultiLatitudVo - QueryDetail")
    public static class QueryDetail {
        @ApiModelProperty("住院就诊流水号")
        private String jzlsh;
        @ApiModelProperty("数据来源")
        private String sjly;
        @ApiModelProperty("入院类型（途径）")
        private String rylx;
        @ApiModelProperty("治疗类别")
        private String ZLLB;
        @ApiModelProperty("医疗付费方式")
        private String YLFFFS;
        @ApiModelProperty("住院次数")
        private String ZYCS;
        @ApiModelProperty("病案号")
        private String BAH;
        @ApiModelProperty("姓名")
        private String XM;
        @ApiModelProperty("性别")
        private String XB;
        @ApiModelProperty("床号")
        private String CH;
        @ApiModelProperty("出生日期")
        private String CSRQ;
        @ApiModelProperty("患者年龄")
        private String HZLN;
        @ApiModelProperty("婚姻状况代码")
        private String HYZKDM;
        @ApiModelProperty("民族代码")
        private String MZDM;
        @ApiModelProperty("出生地名称")
        private String CSDMC;
        @ApiModelProperty("身份证号")
        private String SFZH;
        @ApiModelProperty("患者联系电话")
        private String HZLXDH;
        @ApiModelProperty("职业类别代码")
        private String ZYLBDM;
        @ApiModelProperty("现住址行政区划代码")
        private String XZZXZQHDM;
        @ApiModelProperty("现住址-省（自治区、直辖市）")
        private String XZZSHENG;
        @ApiModelProperty("现住址-市")
        private String XZZSHI;
        @ApiModelProperty("现住址-县/区")
        private String xzzqu;
        @ApiModelProperty("现住址-乡（镇、街道办事处）")
        private String XZZXIANGZHEN;
        @ApiModelProperty("现住址-村（街、路、弄等）")
        private String XZZCUN;
        @ApiModelProperty("现住址-门牌号码")
        private String XZZMPH;
        @ApiModelProperty("居住地（现住址）")
        private String JZD;
        @ApiModelProperty("现住址电话")
        private String XZZDH;
        @ApiModelProperty("现住址邮编")
        private String XZZYB;
        @ApiModelProperty("联系人姓名")
        private String LXRXM;
        @ApiModelProperty("联系人关系")
        private String LXRGX;
        @ApiModelProperty("联系人地址")
        private String LXRDZ;
        @ApiModelProperty("联系人电话")
        private String LXRDH;
        @ApiModelProperty("入院时间")
        private String RYSJ;
        @ApiModelProperty("入院科室名称")
        private String RYKSMC;
        @ApiModelProperty("入院病区（房）")
        private String RYBQ;
        @ApiModelProperty("出院时间")
        private String CYSJ;
        @ApiModelProperty("出院科室名称")
        private String CYKSMC;
        @ApiModelProperty("出院病区（房）")
        private String CYBQ;
        @ApiModelProperty("实际住院天数")
        private String SJZYTS;
        @ApiModelProperty("住院期间是否告知病危或病重")
        private String ZYQJSFGZBWHBZ;
        @ApiModelProperty("住病案执行标准")
        private String BAZXBZ;
        @ApiModelProperty("传染病史")
        private String CRBS;
        @ApiModelProperty("过敏症状出现日期")
        private String GMZZCSRQ;
        @ApiModelProperty("药物过敏源名称")
        private String YWGMYMC;

    }

}
